# -*- coding:utf-8 -*-

import random
print ("四则运算答题器")
operator = ['+', '-', '*', '/']
answer = ""
num= 1
num_true, num_false= 0,0
a='' #用于储存题目

used_a=[]
c=0  #用于跳出循环

Range1=0
Range2=0
b=[1,2,3] #难度系数

q=[]
print("难度选择\n难度1、(1-50)四则运算\n难度2、(50-100)四则运算\n难度3、(100-200)四则运算")
dif = raw_input("请输入难度系数（“1”或“2”或“3”）：")
if (dif in b) and (int(dif)==1):
    Range1=1
    Range2=50
    c=2
elif (dif in b) and (int(dif)==2):
    Range1=50
    Range2=100
    c=2
elif (dif in b) and (int(dif)==3):
    Range1=100
    Range2=200
    c=2
else:
    c=1
while c==1:
    dif = raw_input("无效的难度系数，请从新输入难度系数（“1”或“2”或“3”）：")
    if (dif in b) and (int(dif)==1):
        Range1=1
        Range2=50
        c=2
    elif (dif in b) and (int(dif)==2):
        Range1=50
        Range2=100
        c=2
    elif (dif in b) and (int(dif)==3):
        Range1=100
        Range2=200
        c=2
    else:
        c=1
while num < 10:
    num1 = random.randint(Range1, Range2)
    num2 = random.randint(Range1, Range2)
    op = random.randint(0, 3)
    a = str(num1) + operator[op] + str(num2)  
    while a in used_a:
        num1 = random.randint(Range1, Range2)
        num2 = random.randint(Range1, Range2)
        op = random.randint(0, 3)        
        a = str(num1) + operator[op] + str(num2)        
    used_a.append(a)
    daan = eval(a)
    print( "问题%d: %s=" % (num, a))
    try:
        answer = input("请输入答案: ")
    except :
        answer =input("答案不能为空，请重新输入: ")
        if daan == int(answer):
            print( "回答正确！")
            num_true+=1
        else:
            print ("回答错误，正确答案是： %d" % daan)
            num_false+=1
            
        num += 1
    else:
        if daan == int(answer):
            print( "回答正确！")
            num_true+=1
        else:
            print ("回答错误，正确答案是： %d" % daan)
            num_false+=1
        num += 1
print ("正确的题目数量为%d" % (num_true))
